
export default {
    data() {
        return {
            mixinList_tableDataName: "mixinList_tableData",
            mixinList_tableData: [],
            mixinList_loading: true,
            // 列表动态查询参数
            mixinList_tableSearchData: {},
            // 列表常量查询参数
            mixinList_tableSearchConst: {},
            //   分页
            mixinList_pageData: {
                // 当前页
                pageNum: 1,
                // 每页显示条数
                pageSize: this.$vFN.Constants.pageSize,
                // 总条数
                total: 0,
                // 总页数
                totalPage: 0,
            },
            // 选择表格的数据 用于对表格的批量操作
            mixinList_selectTableData: [],
            // 表格数据类型  list | tree
            mixinList_tableDataType: "list",
        }
    },
    methods: {
        // 选择表格时
        mixinList_handleSelectionChangeTableSmall(val_) {
            this.mixinList_selectTableData = val_;
        },
        // 取消选择
        mixinList_clearSelectionChangeTableSmall() {
            this.$refs[this.mixinPage_vueName + 'TableSmall'].clearSelection();
        },
        /**
         * 删除表格数据
         * @param {*} ids 数组 id
         */
        async mixinList_selectTableDeleteData(data_) {
            if (!data_) {
                data_ = [...this.mixinList_selectTableData]
            }

            // console.error("this.$vFN",this.$vFN.Directives.)
            this.$vFN.Directives.TableDeleteBox({
                appWindow: this.appWindow,
                data: data_,
                config: this.tableDeleteConfig,
                url: this.apiUrl.delete,
                onSuccess: () => {
                    this.$vFN.Tools.messageSuccess("删除成功");
                    this.mixinList_getTable(this.mixinList_pageData.pageNum);
                },
            })

        },

        async mixinList_getTableValidate(data_) {
            // console.error("mixinList_getTableValidate",data_)
            return true
        },
        /**
         * 获取表格数据列表
         * @param {*} pageNum_ 选填，不传时为刷新本页，
         */
        async mixinList_getTable(pageNum_) {
            if (!pageNum_) {
                pageNum_ = this.mixinList_pageData.pageNum;
            }
            this.mixinList_loading = true;
            let _d = {
                // delayTime: 1000,
                data: { ...this.mixinList_tableSearchData, ...this.mixinList_tableSearchConst },
            }
            if (typeof this.apiUrl.list == "object") {
                _d.url = this.apiUrl.list.url;
                _d.domain = this.apiUrl.list.domain;
            }
            else {
                _d.url = this.apiUrl.list;
            }
            // 表格数据格式返回的数据格式不同 list 支持分页 ，tree不支持分页
            if (this.mixinList_tableDataType == "list") {
                _d.params = {
                    pageNum: pageNum_,
                    pageSize: this.mixinList_pageData.pageSize,
                }
            }
            let _is = await this.mixinList_getTableValidate(_d);
            if(!_is){
                this.mixinList_loading = false;
                return
            }
            let _data = await this.$vFN.Http.post(_d, this.appWindow);
            if (_data._ok) {
                // 表格数据格式返回的数据格式不同 list 支持分页 ，tree不支持分页
                if (this.mixinList_tableDataType == "list") {
                    this[this.mixinList_tableDataName] = await this.mixinList_getTableExtend(_data.data.list);
                    this.mixinList_setPageData(_data.data);
                } else if (this.mixinList_tableDataType == "tree") {
                    this[this.mixinList_tableDataName] = await this.mixinList_getTableExtend(_data.data);
                }
            }
            this.mixinList_loading = false;
        },
        // 扩展方法，
        async mixinList_getTableExtend(data_) {
            return data_
        },
        // 设置分页数据
        mixinList_setPageData(data_) {
            this.mixinList_pageData.pageNum = data_.pageNum - 0;
            this.mixinList_pageData.total = data_.total - 0;
            this.mixinList_pageData.totalPage = data_.totalPage - 0;

        },

        // 分页跳转
        mixinList_pagingData(e) {
            this.mixinList_getTable(e);
        },


        // 更新页面回调
        async mixinList_refreshData() {
            await this.mixinList_getTable(1);
        },

        //自定义索引
        mixinList_indexMethod(index) {
            return (
                index +
                1 +
                (this.mixinList_pageData.pageNum - 1) * this.mixinList_pageData.pageSize
            );
        },
    },
    mounted() {
        let that = this;
        this.$nextTick(() => { });

    },
    watch: {
    },
}